<?xml version="1.0" encoding="UTF-8" ?>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="/common/base.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Insert title here</title>
<link href="${ctsCss}/table.css" rel="stylesheet" type="text/css" />
</head>
<body>
<%@ include file="/common/message-save.jsp" %>
<form id="category-form" class="form-horizontal" action="${ctx}/reportStatCategoryController/<c:choose><c:when test="${rptTemplateStatCategory.id == null}">insertReportStatCategory</c:when><c:otherwise>updateReportStatCategory</c:otherwise></c:choose>" method="post">
	<input type="hidden" id="id" name="id" value="${rptTemplateStatCategory.id}"/>
	<input type="hidden" id="dataSetSelectId" value="${rptTemplateStatCategory.setId}"></input>
	<input type="hidden" id="dataItemSelectId" value="${rptTemplateStatCategory.itemId}"></input>
	<input type="hidden" id="itemStatTimeSelectId" value="${rptTemplateStatCategory.itemStatTimeId}"></input>
	<input type="hidden" id="itemUnitIdSelectId" value="${rptTemplateStatCategory.itemUnitId}"></input>
<table>
	 <tr class="tab_grey">
	      <td width="25%">区域名称：</td>
	      <td width="75%">
	      	<input type="text" id="name" name="categoryName" value="${rptTemplateStatCategory.categoryName }" required maxlength="50" style="width:200px" maxlength='25' />
	      </td>
     </tr>
     <tr class="tab_grey">
	      <td width="25%">统计信息集：</td>
	      <td width="75%" colspan="3">
	      		<select id="dataSetSelect" name="setId" class="dataSetSelectClass" required onchange="loadDataItemList();loadDataItemTimeList();loadDataItemUnitList();"></select>
	      </td>
     </tr>
     <tr class="tab_grey">
	      <td width="25%">统计时间类型：</td>
		  <td width="75%" colspan="3">
		      	<select id="itemStatTimeSelect" name="itemStatTimeId"  class="itemStatTimeSelectClass"></select>
		  </td>
     </tr>
     <tr class="tab_grey">
	      <td width="25%">所在党组织：</td>
		  <td width="75%" colspan="3">
		      	<select id="itemUnitIdSelect" name="itemUnitId"  required class="itemUnitIdSelectClass"></select>
		  </td>
     </tr>
</table>
<div  style="text-align: center;">
	<button type="button" class="btn btn-primary" id="saveBtn" onclick="categorySaveInfo();">保存</button>
	<button type="reset" class="btn" id="resetBtn">重置</button>
</div>
</form>
</body>
<script type="text/javascript">
$('#category-form').validate();

function categorySaveInfo(){
	$("#category-form").submit();
}

$(document).ready(function(){
	loadDataSet();
});

//选择数据集后加载数据项
function loadDataItemList(){
	var setId = $("#dataSetSelect").val();
	var dataItemSelectId = $("#dataItemSelectId").val();
	$.ajax({
		url:'${ctx}/reportTemplateConditionsController/getAllDataItemBySetId/' + setId,
		type:'POST',
		cache:false,
		success:function(data){
			var dataItemOptions = "";
		    $.each(data,function(idx,item){
		    	if(item.id==dataItemSelectId){
		    		dataItemOptions += "<option value='" + item.id + "' selected>" + item.itemChineseName + "</option>";
		    	}else{
		    		dataItemOptions += "<option value='" + item.id + "'>" + item.itemChineseName + "</option>";
		    	}
			});
		    $("#dataItemSelect option").remove();
		    dataItemOptionsFirst="<option value=''>请选择</option>";
		    $(".dataItemSelectClass").append(dataItemOptionsFirst).append(dataItemOptions);
		}
	});
}

//加载数据集
function loadDataSet(){
	var dataSetSelectId = $("#dataSetSelectId").val();
	var dataItemSelectId = $("#dataItemSelectId").val();
	$.ajax({
		url:'${ctx}/reportTemplateConditionsController/getAllDataSet',
		type:'POST',
		cache:false,
		success:function(data){
			var dataSetOptions = "";
		    $.each(data,function(idx,item){
		    	if(dataSetSelectId == item.id){
		    		dataSetOptions += "<option value='" + item.id + "' selected>" + item.chineseName + "</option>";
		    	}else{
		    		dataSetOptions += "<option value='" + item.id + "'>" + item.chineseName + "</option>";
		    	}
			});
		    $("#dataSetSelect option").remove();
		    dataSetOptionsFirst="<option value=''>请选择</option>";
		    $(".dataSetSelectClass").append(dataSetOptionsFirst).append(dataSetOptions);
		    if(dataSetSelectId != null && dataItemSelectId != null){
		    	loadDataItemList();
		    	loadDataItemTimeList();
		    	loadDataItemUnitList();
		    }
		}
	});
}

//选择数据集后加载时间字段选择
function loadDataItemTimeList(){
	var setId = $("#dataSetSelect").val();
	var itemStatTimeSelectId = $("#itemStatTimeSelectId").val();
	$.ajax({
		url:'${ctx}/reportTemplateConditionsController/getAllDataItemBySetId/' + setId,
		type:'POST',
		cache:false,
		success:function(data){
			var dataItemOptions = "";
		    $.each(data,function(idx,item){
		    	if(item.id==itemStatTimeSelectId){
		    		dataItemOptions += "<option value='" + item.id + "' selected>" + item.itemChineseName + "</option>";
		    	}else{
		    		dataItemOptions += "<option value='" + item.id + "'>" + item.itemChineseName + "</option>";
		    	}
			});
		    $("#itemStatTimeSelect option").remove();
		    dataItemOptionsFirst="<option value=''>请选择</option>";
		    $(".itemStatTimeSelectClass").append(dataItemOptionsFirst).append(dataItemOptions);
		}
	});
}

//选择数据集后加载单位字段选择
function loadDataItemUnitList(){
	var setId = $("#dataSetSelect").val();
	var itemUnitIdSelectId = $("#itemUnitIdSelectId").val();
	$.ajax({
		url:'${ctx}/reportTemplateConditionsController/getAllDataItemBySetId/' + setId,
		type:'POST',
		cache:false,
		success:function(data){
			var dataItemOptions = "";
		    $.each(data,function(idx,item){
		    	if(item.id==itemUnitIdSelectId){
		    		dataItemOptions += "<option value='" + item.id + "' selected>" + item.itemChineseName + "</option>";
		    	}else{
		    		dataItemOptions += "<option value='" + item.id + "'>" + item.itemChineseName + "</option>";
		    	}
		    	
			});
		    $("#itemUnitIdSelect option").remove();
		    dataItemOptionsFirst="<option value=''>请选择</option>";
		    $(".itemUnitIdSelectClass").append(dataItemOptionsFirst).append(dataItemOptions);
		}
	});
}
</script>
</html>